//
//  ZJThreeButtonView.swift
//  Webo
//
//  Created by 曾静 on 16/6/27.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit

class ZJThreeButtonView: UIView {
    
    
    
    var status:ZJStatues?{
        
        didSet{
            
//            //	int	转发数
//            var reposts: String?
//            //	int	评论数
//            var comments: String?
//            //	int	表态数
//            var attitudes: String?
            firstButton?.setTitle(status?.reposts, forState: UIControlState.Normal)
            secondButton?.setTitle(status?.comments, forState: UIControlState.Normal)
            thirdButton?.setTitle(status?.attitudes, forState: UIControlState.Normal)
            
        }
    }

    //button定义为可选项的类型必须为var的类型
    var firstButton:UIButton?
    
    var secondButton:UIButton?
    
    var thirdButton:UIButton?
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   
    
    //创建视图
    func  setupUI(){
        
//        addSubview(pictureView)
        
        //创建按钮
        firstButton = addButton("timeline_icon_retweet", title: "转发")
        
        secondButton = addButton("timeline_icon_comment", title: "评论")
        
        thirdButton = addButton("timeline_icon_unlike", title: "赞")
        
        //创建分隔线
        let line1 = addLines()
        
        let line2 = addLines()
        
        //为三个按钮创建约束
        
        firstButton?.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.bottom.equalTo(self)
            
            make.width.equalTo(secondButton!)
            
        }
        secondButton?.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            
            make.leading.equalTo(firstButton!.snp_trailing)
            
            make.width.equalTo(thirdButton!)
            
        }
        
        
        thirdButton?.snp_makeConstraints { (make) -> Void in
            
            make.top.trailing.bottom.equalTo(self)
            
            make.leading.equalTo(secondButton!.snp_trailing)
            
            
        }
        
        
        ///不设置宽度的话.默认是自适应的
        line1.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            
            make.centerX.equalTo(firstButton!.snp_trailing)
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            
            make.centerX.equalTo(secondButton!.snp_trailing)
        }
        

    }
    
    
    
    //创建添加btn的方法
    func addButton(imageName:String,title:String) ->UIButton{
        
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        button.setTitle(title, forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        
        addSubview(button)
        
        return button
    }
    
    func addLines()->UIImageView{
        
        let lineView = UIImageView(imageName: "timeline_card_bottom_line")
        
        addSubview(lineView)
        
        return lineView
    }
}
